package File;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Code {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String data = "a鹅b";
        // 按照默认字符集编码，输出每个字节
        byte[] bytes = data.getBytes();
        System.out.println(Arrays.toString(bytes)); // [97, -23, -71, -123, 98]
        // 按照指定字符集编码
        byte[] bytes1 = data.getBytes("GBK");
        System.out.println(Arrays.toString(bytes1)); // [97, -74, -20, 98]

        // 按照默认字符集解码，输出内容
        String s1 = new String(bytes);
        System.out.println(s1); // a鹅b
        // 按照指定字符集解码
        String s2 = new String(bytes1, "GBK");
        System.out.println(s2); // a鹅b
    }
}
